//
//  MenuLayer.cpp
//  ATM Killer
//
//  Created by USoft on 7/23/14.
//
//

#include "MenuLayer.h"
MenuLayer::MenuLayer() {
    this->initialize();
}

MenuLayer::~MenuLayer() {
    
}

void MenuLayer::onEnter() {
    Layer::onEnter();
}

void MenuLayer::onExit() {
    Layer::onExit();
    this->removeAllChildrenWithCleanup(true);
}
void MenuLayer::update(float dt) {
    GameModel* gameModel = GameModel::getInstance();
    UGMenu* menu = (UGMenu*) this->pauseBoard->getChildByTag(0);
    if(gameModel->getGameState() == GS_PAUSE)
    {
        this->grayLayer->setVisible(true);
        this->mainLayer->setVisible(true);
        menu->setEnabled(true);
    }
    else
    {
        menu->setEnabled(false);
        this->grayLayer->setVisible(false);
        this->mainLayer->setVisible(false);
    }
}
void MenuLayer::initialize() {
    this->mainLayer = 0;
    this->createLayers();
    this->createLayersContent();
}
void MenuLayer::createLayers()
{
    this->grayLayer = UGLayerColor::create();
    this->grayLayer->initWithColor(Color4B(0,0,0,100));
    this->addChild(this->grayLayer);
    
    this->mainLayer = UGLayer::create();
    this->addChild(this->mainLayer);
}
void MenuLayer::createLayersContent()
{
    GameModel* gameModel = GameModel::getInstance();
    Size gameSize = gameModel->getDisplayResolutionSize();
    //pauseBoard
    this->pauseBoard = new Face();
    this->pauseBoard->initWithSpriteFrameName(ANI_PAUSE_BOARD);
    this->pauseBoard->setPosition(gameSize.width/2, gameSize.height/2);
    this->mainLayer->addChild(this->pauseBoard);
    Size pauseBoardSize = this->pauseBoard->getContentSize();

    UGMenu* menu = UGMenu::create();
    menu->setPosition(Point::ZERO);
    this->pauseBoard->addChild(menu);
    menu->setTag(0);
    //resume button
    {
        this->resumeButton = Utils::createButton((char*)ANI_BUTTON_GREEN, (char*)ANI_BUTTON_RED, (char*)"Continue game", 35, (char*)FONT_TRANSFORMER, Color3B(255,255,255));
        this->resumeButton->setPosition(pauseBoardSize.width/2, pauseBoardSize.height - 110);
        menu->addChild(this->resumeButton);
    }
    //achievement button
    {
        this->achievementButton = Utils::createButton((char*)ANI_BUTTON_GREEN, (char*)ANI_BUTTON_RED, (char*)"Achievements", 35, (char*)FONT_TRANSFORMER, Color3B(255,255,255));
        this->achievementButton->setPosition(pauseBoardSize.width/2, this->resumeButton->getPositionY() - this->resumeButton->getContentSize().height - 5);
        menu->addChild(this->achievementButton);
    }
    //stat button
    {
        this->statButton = Utils::createButton((char*)ANI_BUTTON_GREEN, (char*)ANI_BUTTON_RED, (char*)"Statistics", 35, (char*)FONT_TRANSFORMER, Color3B(255,255,255));
        this->statButton->setPosition(pauseBoardSize.width/2, this->achievementButton->getPositionY() - this->achievementButton->getContentSize().height - 5);
        menu->addChild(this->statButton);
    }
    //option button
    {
        this->optionButton = Utils::createButton((char*)ANI_BUTTON_GREEN, (char*)ANI_BUTTON_RED, (char*)"Option", 35, (char*)FONT_TRANSFORMER, Color3B(255,255,255));
        this->optionButton->setPosition(pauseBoardSize.width/2, this->statButton->getPositionY() - this->statButton->getContentSize().height - 5);
        menu->addChild(this->optionButton);
    }
    //Conversion
    {
        this->conversionButton = Utils::createButton((char*)ANI_BUTTON_GREEN, (char*)ANI_BUTTON_RED, (char*)"Conversion", 35, (char*)FONT_TRANSFORMER, Color3B(255,255,255));
        this->conversionButton->setPosition(pauseBoardSize.width/2, this->optionButton->getPositionY() - this->optionButton->getContentSize().height - 5);
        menu->addChild(this->conversionButton);
    }
    //reset button
    {
        this->resetButton = Utils::createButton((char*)ANI_BUTTON_GRAY, (char*)ANI_BUTTON_GRAY, (char*)"Auto Click", 35, (char*)FONT_TRANSFORMER, Color3B(255,255,255));
        this->resetButton->setPosition(pauseBoardSize.width/2, this->optionButton->getPositionY() - 2 * this->optionButton->getContentSize().height - 10);
        Face* lock = new Face();
        lock->initWithSpriteFrameName(ANI_ICO_LOCK);
        lock->setPosition(35, lock->getContentSize().height/2+5);
        this->resetButton->addChild(lock);
        menu->addChild(this->resetButton);
    }
}
